#!/usr/bin/env node

const mysql = require('mysql2/promise'),
      log = console.log;

let con = mysql.createPool({
  host : '127.0.0.1',
  user : 'root',
  password : 'ddd',
  database : 'test'
});

async function updateArea(oldName,newName){
  const sql = `update areas set area_name = '${newName}' where area_name = '${oldName}'`;
  let [rows] = await con.execute(sql);
  return rows;
}

async function delArea(id){
    const sql = `delete from areas where id = ${id}`;
    let [rows] = await con.execute(sql);
    return rows;
}


async function addArea(areaName){
  const sql = `insert into areas(area_name) values('${areaName}')`;
  let [rows] = await con.execute(sql);
  return rows;
}


async function getAreas(){
  const sql = 'select * from areas';

  let [rows] = await con.execute(sql);

  return rows;
}

(async function(){
  //await delArea(9);
  //await updateArea('英国','大不列颠');
  //await addArea('英国');
  log(await getAreas());
})();
